/**
 * Created by lixiaodi on 2018/11/10.
 */
mini.parse();
var form = new mini.Form("sqlForm");
//保存
function save(){
    //得到表单数据
    var ids = form.getData();
    console.log(ids);
    var dataObj = {
        reportId : ids.reportId,
        reportName : ids.reportName,
        ipAddress : ids.ipAddress,
        dbName : ids.dbName,
        JDBCDriver : ids.jDBCDriver,
        JDBCUserName : ids.jDBCUserName,
        JDBCPassword : ids.jDBCPassword,
        sql : ids.sql,
        whereParam : ids.whereParam,
        createDate : "",
        updateDate : "",
        JDBCUrl : ""
    }
    var jsonString = JSON.stringify(dataObj);
    $.ajax({
        url : ajaxUrl +"/ReportParamController/createReportParam.do",
        type : "POST",
        contentType: 'application/json',
        data : jsonString,
        success : function(data){
            CloseWindow("save");
        },
        error : function(data){
            CloseWindow();
        }
    })
}
//设置
function searchDet(){
    //得到表单数据
    var formId = form.getData();
    var id = formId.reportId;
    console.log(id);
    mini.open({
        url        : bootPATH + '../frame/frame1/pages/reportForm/queryList.html',
        title      : "条件查询列表",
        width      : 900,
        height     : 460,
        onload     : function(){
            var iframe = this.getIFrameEl();
            //用data.action判断是新增页面还是编辑页面
            var data = {action : "new",reportId : id};
            iframe.contentWindow.SetData(data);
        },
        ondestroy  : function(){
            grid.reload();
        }
    });
}
//赋值
function SetData(data) {
    //如果编辑
    if (data.action == "edit") {
        //跨页面传递的数据对象，克隆后才可以安全使用
        data = mini.clone(data);
        var reportId = data.reportId;
        $.ajax({
            url: ajaxUrl + "/ReportParamController/FindReportParam.do?id=" + reportId,
            type : "POST",
            success: function (data) {
                var o = mini.decode(data);
                form.setData(o.data);
                form.setChanged(false);
            },
            error:function(data){
                mini.alert('失败');
            }
        });
        //如果新增
    }else if(data.action == "new"){
        console.log("new");
    }
}
//关闭按钮
function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
        if (confirm("数据被修改了，是否先保存?")) {
            return false;
        }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}
function onOk(e) {
    SaveData();
}
function onCancel(e) {
    CloseWindow("cancel");
}